﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;

namespace 数据转换小工具
{
    public partial class Progress : Form
    {
        private int _successsum = 0;
        private int _failsum = 0;
        private int _allsum = 0;
        private DateTime _startime = new DateTime();
        private string _tableold = string.Empty;
        private string _tablenew = string.Empty;

        /// <summary>
        /// 成功的数量。
        /// </summary>
        public int SuccessSum
        {
            get { return _successsum; }
            set 
            {
                _successsum = value;
                progressBar1.Value = _successsum + _failsum;
                lbSuccessSum.Text = _successsum.ToString();
                lbLv.Text = ((double)_successsum / _allsum*100).ToString("0.00")+"%";
                lbPro.Text = ((double)(_successsum + _failsum) / _allsum * 100).ToString("0.00") + "%";
                if (_successsum + _failsum == _allsum)
                    timer1.Enabled = false;
            }
        }

        /// <summary>
        /// 失败的数量。
        /// </summary>
        public int FailSum
        {
            get { return _failsum; }
            set
            {
                _failsum = value;
                progressBar1.Value = _successsum + _failsum;
                lbFailSum.Text=_failsum.ToString();
                lbLv.Text = ((double)_successsum / _allsum * 100).ToString("0.00") + "%";
                lbPro.Text = ((double)(_successsum + _failsum) / _allsum * 100).ToString("0.00") + "%";
                if (_successsum + _failsum == _allsum)
                    timer1.Enabled = false;
            }
        }

        /// <summary>
        /// 总的数量。
        /// </summary>
        public int AllSum
        {
            get { return _allsum; }
            set
            { 
                _allsum = value;
                progressBar1.Maximum = _allsum;
                lbAllSum.Text = _allsum.ToString();
            }
        }
        /// <summary>
        /// 开始时间
        /// </summary>
        public DateTime StarTime
        {
            get { return _startime; }
            set { _startime = value; }
        }

        /// <summary>
        /// 要转的表名
        /// </summary>
        public string Tableold
        {
            get { return _tableold; }
            set
            { 
                _tableold = value;
                lbTableOld.Text = _tableold;
            }
        }
        /// <summary>
        /// 要转入的表名
        /// </summary>
        public string TableNew
        {
            get { return _tablenew; }
            set
            {
                _tablenew = value;
                lbTableNew.Text = _tablenew;
            }
        }
        public Progress()
        {
            InitializeComponent();
            _startime = DateTime.Now;
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            // 耗时。
            lbUseTime.Text = (DateTime.Now - _startime).TotalSeconds.ToString().Split('.')[0]+" s";
        }
        /// <summary>
        /// 查看错误日志。
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button1_Click(object sender, EventArgs e)
        {
            ProcessStartInfo psi = new ProcessStartInfo(Application.StartupPath + "\\日志\\Debug.txt");
            Process p = new Process();
            p.StartInfo = psi;
            p.Start();     
        }
    }
}
